xlat lib: Use mmap_attr_t type consistently
authorSandrine Bailleux <[email protected]>
Wed, 19 Apr 2017 13:02:23 +0000 (14:02 +0100)
committerSandrine Bailleux <[email protected]>
Thu, 20 Apr 2017 12:01:24 +0000 (13:01 +0100)
This patch modifies both versions of the translation table library
to use the mmap_attr_t type consistently wherever it is manipulating
MT_* attributes variables. It used to use mmap_attr_t or plain integer
types interchangeably, which compiles fine because an enumeration type
can be silently converted to an integer, but which is semantically
incorrect.

This patch removes this assumption by using the abstract type
'mmap_attr_t' all the time.

Change-Id: Id1f099025d2cb962b275bb7e39ad2c4dbb4e366c
Signed-off-by: Sandrine Bailleux <[email protected]>
include/lib/xlat_tables/xlat_tables.h
include/lib/xlat_tables/xlat_tables_v2.h
lib/xlat_tables/xlat_tables_common.c
lib/xlat_tables_v2/xlat_tables_common.c
lib/xlat_tables_v2/xlat_tables_internal.c

index 4e855032b9f0a13ac8528b973de863d78b969efc..38150f52454e277448d8114176cb4ef9d21b8eea 100644 (file)
@@ -108,7 +108,7 @@ typedef struct mmap_region {
 /* Generic translation table APIs */
 void init_xlat_tables(void);
 void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
-                               size_t size, unsigned int attr);
+                               size_t size, mmap_attr_t attr);
 void mmap_add(const mmap_region_t *mm);
 
 #endif /*__ASSEMBLY__*/
index 16b857cc682e165b8e9c1baf514bb743718bb637..d1704b7b4afdc87d845af3cba92833c6d103f9d2 100644 (file)
@@ -114,7 +114,7 @@ void init_xlat_tables(void);
  * be added before initializing the MMU and cannot be removed later.
  */
 void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
-                               size_t size, unsigned int attr);
+                               size_t size, mmap_attr_t attr);
 
 /*
  * Add a region with defined base PA and base VA. This type of region can be
@@ -128,7 +128,7 @@ void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
  *    EPERM: It overlaps another region in an invalid way.
  */
 int mmap_add_dynamic_region(unsigned long long base_pa, uintptr_t base_va,
-                               size_t size, unsigned int attr);
+                               size_t size, mmap_attr_t attr);
 
 /*
  * Add an array of static regions with defined base PA and base VA. This type
index 81c4dc6834d78fb3c5104ef54982f44db5bfe0ae..a5bc095201388d8990c1bbd05a5ccc1870f98439 100644 (file)
@@ -87,7 +87,7 @@ void print_mmap(void)
 }
 
 void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
-                       size_t size, unsigned int attr)
+                       size_t size, mmap_attr_t attr)
 {
        mmap_region_t *mm = mmap;
        mmap_region_t *mm_last = mm + ARRAY_SIZE(mmap) - 1;
@@ -199,7 +199,7 @@ void mmap_add(const mmap_region_t *mm)
        }
 }
 
-static uint64_t mmap_desc(unsigned attr, unsigned long long addr_pa,
+static uint64_t mmap_desc(mmap_attr_t attr, unsigned long long addr_pa,
                                                        int level)
 {
        uint64_t desc;
@@ -277,11 +277,11 @@ static uint64_t mmap_desc(unsigned attr, unsigned long long addr_pa,
  * attributes of the innermost region that contains it. If there are partial
  * overlaps, it returns -1, as a smaller size is needed.
  */
-static int mmap_region_attr(mmap_region_t *mm, uintptr_t base_va,
+static mmap_attr_t mmap_region_attr(mmap_region_t *mm, uintptr_t base_va,
                                        size_t size)
 {
        /* Don't assume that the area is contained in the first region */
-       int attr = -1;
+       mmap_attr_t attr = -1;
 
        /*
         * Get attributes from last (innermost) region that contains the
@@ -360,7 +360,8 @@ static mmap_region_t *init_xlation_table_inner(mmap_region_t *mm,
                         * there are partially overlapping regions. On success,
                         * it will return the innermost region's attributes.
                         */
-                       int attr = mmap_region_attr(mm, base_va, level_size);
+                       mmap_attr_t attr = mmap_region_attr(mm, base_va,
+                                                       level_size);
                        if (attr >= 0) {
                                desc = mmap_desc(attr,
                                        base_va - mm->base_va + mm->base_pa,
index b4691a2b4c0f7719d95cf06d4874a967d4889d6e..7ca81b9c8008e756550a42f4c564acb5991fa631 100644 (file)
@@ -92,7 +92,7 @@ xlat_ctx_t tf_xlat_ctx = {
 };
 
 void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
-                       size_t size, unsigned int attr)
+                       size_t size, mmap_attr_t attr)
 {
        mmap_region_t mm = {
                .base_va = base_va,
@@ -114,7 +114,7 @@ void mmap_add(const mmap_region_t *mm)
 #if PLAT_XLAT_TABLES_DYNAMIC
 
 int mmap_add_dynamic_region(unsigned long long base_pa,
-                           uintptr_t base_va, size_t size, unsigned int attr)
+                           uintptr_t base_va, size_t size, mmap_attr_t attr)
 {
        mmap_region_t mm = {
                .base_va = base_va,
index 2f03306e9cd7d7f79610db9a014c283e35b43e2f..581f77032418fff742e728ba197abae7fc568fc8 100644 (file)
@@ -115,7 +115,7 @@ static uint64_t *xlat_table_get_empty(xlat_ctx_t *ctx)
 #endif /* PLAT_XLAT_TABLES_DYNAMIC */
 
 /* Returns a block/page table descriptor for the given level and attributes. */
-static uint64_t xlat_desc(unsigned int attr, unsigned long long addr_pa,
+static uint64_t xlat_desc(mmap_attr_t attr, unsigned long long addr_pa,
                          int level)
 {
        uint64_t desc;
@@ -609,7 +609,7 @@ void print_mmap(mmap_region_t *const mmap)
  */
 static int mmap_add_region_check(xlat_ctx_t *ctx, unsigned long long base_pa,
                                 uintptr_t base_va, size_t size,
-                                unsigned int attr)
+                                mmap_attr_t attr)
 {
        mmap_region_t *mm = ctx->mmap;
        unsigned long long end_pa = base_pa + size - 1;